home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-12-05 | 2.1 KB | 100 lines | [TEXT/MPS ] |
- c
- c Returns the N-th word (space delimited)
- c
- c Function CharWord
- c Takes a character and an integer*4 word number as input.
- c Returns a character*(*) (word n) as result.
- c note: words are separated by whitespace
- c
- c Example provided for owners of Language Systems FORTRAN
- c © 1990 Language Systems Corp.
- c
- c Adapted from a routine in Wild Things.
- c
- character*(*) function CharWord(theCharacter,theWordNumber)
-
- C receive the argument by Descriptor
-
- structure /DescRec/
- pointer /character*1/ DataPtr
- integer*2 DataSize
- integer*2 SymT
- end structure
- record /DescRec/ theCharacter
-
- integer*4 chard,strngd
- parameter (chard=18,strngd=19)
-
- integer*4 CharacterLen,theWordNumber
- integer*4 Word,startC,stopC
- logical*4 WhiteSpace
-
- pointer /character*1/ ptr1,ptr2,ptr3
-
- C put the address of the characters into a local variable
-
- ptr1 = theCharacter.DataPtr
-
- C store the size
-
- CharacterLen = theCharacter.DataSize
-
- c skip any words we don't want
-
- ptr2 = ptr1
- Word = 1
- do while (Word < theWordNumber)
- do while ((WhiteSpace(ptr2)) .and. ((ptr2-ptr1) < CharacterLen))
- ptr2 = ptr2 + 1
- end do
- do while ((.not. WhiteSpace(ptr2)) .and. ((ptr2-ptr1) < CharacterLen))
- ptr2 = ptr2 + 1
- end do
- Word = Word + 1
- end do
-
- c skip any white space before desired word
-
- do while ((WhiteSpace(ptr2)) .and. ((ptr2-ptr1) < CharacterLen))
- ptr2 = ptr2 + 1
- end do
- startC = 1 + (ptr2 - ptr1)
-
- c find the end of the word
-
- ptr3 = ptr2
- do while ((.not. WhiteSpace(ptr3)) .and. ((ptr3-ptr1) < CharacterLen))
- ptr3 = ptr3 + 1
- end do
- stopC = startC + (ptr3 - ptr2) - 1
- if (stopC < startC) stopC = startC
-
- c return the word (turn range checking off)
- !!R-
- CharWord = ptr1^(startC:stopC)
-
- return
- end
- c
- c**************************************************c
- c
- c Function WhiteSpace
- c Takes a pointer to a character as input.
- c Returns a logical*4 TRUE if the character
- c is a tab,return or space.
- c
- logical*4 function WhiteSpace(ptr)
-
- pointer /byte/ ptr
-
- select case(ptr^)
- case(9,13,32) !ASCII values of tab, return, space
- WhiteSpace = .true.
- case default
- WhiteSpace = .false.
- end select
- return
- end
- c
- c****************************************c
-